package com.ctrip.cap.appium;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * @author ltyao
 *
 */
public class PopupUtils {

	private static final Logger logger = LoggerFactory
			.getLogger(PopupUtils.class);

	/**
	 * 点击类似立即更新 按钮 默认等待0seconds
	 * 
	 * @param ignoreButton
	 * @param driver
	 */
	public static void ignoreUpdate(By ignoreButton, WebDriver driver) {
		ignoreUpdate(ignoreButton, driver, 0);

	}

	/**
	 * 点击类似立即更新 按钮 默认等待3seconds
	 * 
	 * @param ignoreButton
	 * @param driver
	 */
	public static void ignoreUpdate(By ignoreButton, WebDriver driver,
			long timeoutInSeconds) {
		try {
			new WebDriverWait(driver, timeoutInSeconds).withMessage(
					"Wait Popup button exist " + ignoreButton).until(
					ExpectedConditions.presenceOfElementLocated(ignoreButton));

			WebElement element = driver.findElement(ignoreButton);
			element.click();
		} catch (Exception e) {
			logger.warn(
					"ignoreUpdate failed with Locator {},but we ignored it",
					ignoreButton);
		}

	}

}
